/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */

package com.hopes.bizz.stop.manage.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.hopes.bizz.close.common.api.feign.RemoteClosedHazardApplyService;
import com.hopes.bizz.close.visitor.entity.ClosedApplyGoodsRelEntity;
import com.hopes.bizz.stop.common.constant.enums.ParkStopSysDictEnum;
import com.hopes.boss.admin.api.resolver.DictResolver;
import com.hopes.boss.admin.api.resolver.enums.AdminDictEnum;
import com.hopes.boss.common.core.constant.SecurityConstants;
import com.hopes.boss.common.core.util.SpringContextHolder;
import com.hopes.boss.common.entity.BaseLogicEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 园区车辆准入清单
 *
 * @author pig
 * @date 2024-02-26 10:50:29
 */
@Data
@TableName("closed_drive_in_car_list")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "园区车辆准入清单")
public class ClosedDriveInCarListEntity extends BaseLogicEntity {

    private static final long serialVersionUID = 1L;


    /**
     * 标识
     */
    @TableId(type = IdType.ASSIGN_ID)
    @Schema(description = "标识")
    private Long id;

    /**
     * 到访企业
     */
    @Schema(description = "到访企业")
    private Long companyId;

    /**
     * 运单号
     */
    @Schema(description = "运单号")
    private String waybillNumber;

    /**
     * 预约车位
     */
    @Schema(description = "预约车位")
    private String subCarport;

    /**
     * 车位id
     */
    @Schema(description = "车位id")
    private Long subCarportId;


    /**
     * 开始时间
     */
    @Schema(description = "开始时间")
    private LocalDateTime inDate;

    /**
     * 结束时间
     */
    @Schema(description = "结束时间")
    private LocalDateTime outDate;

    /**
     * 实际开始时间
     */
    @Schema(description = "实际开始时间")
    private LocalDateTime relInDate;

    /**
     * 实际结束时间
     */
    @Schema(description = "实际结束时间")
    private LocalDateTime relOutDate;

    /**
     * 备注
     */
    @Schema(description = "备注")
    private String remark;

    /**
     * 车辆
     */
    @Schema(description = "车辆")
    private Long carId;

    /**
     * 车牌号
     */
    @Schema(description = "车牌号")
    private String plateNumber;

    /**
     * 车辆类型
     */
    @Schema(description = "车辆类型")
    private Long carType;

    /**
     * 停车状态
     */
    @Schema(description = "停车状态")
    private Integer stopStatus;

    /**
     * 机构ID
     */
    @Schema(description = "机构ID")
    private Long orgId;

    public String getStopStatusStr() {
        return DictResolver.getItemLabelByValue(ParkStopSysDictEnum.stop_status, this.stopStatus);
    }

    public String getCompanyIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_company, this.companyId);
    }

    public String getCarTypeStr() {
        return DictResolver.getItemLabelByValue(ParkStopSysDictEnum.stop_car_type, this.carType);
    }


    public List<ClosedApplyGoodsRelEntity> getClosedApplyGoodsRelList() {
        return
                Optional.of(SpringContextHolder.getBean(RemoteClosedHazardApplyService.class).queryHazardApplyByBillNo(this.waybillNumber, SecurityConstants.FROM_IN)
                        .getData()).get().getClosedApplyGoodsRelList();
    }

    public String getHazardTypeStr() {
        return
                Optional.of(SpringContextHolder.getBean(RemoteClosedHazardApplyService.class).queryHazardApplyByBillNo(this.waybillNumber, SecurityConstants.FROM_IN)
                        .getData()).get().getHazardTypeStr();
    }


}
